#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include "cmd_thread.h"

pthread_mutex_t vctrl_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t  vctrl_start_ready = PTHREAD_COND_INITIALIZER;
pthread_cond_t  vctrl_over_ready = PTHREAD_COND_INITIALIZER;
pthread_t       vctrl_thread;

pthread_mutex_t net_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t  net_ready = PTHREAD_COND_INITIALIZER;
pthread_t       net_thread;


pthread_mutex_t vcap_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t  vcap_start_ready = PTHREAD_COND_INITIALIZER;
pthread_cond_t  vcap_over_ready = PTHREAD_COND_INITIALIZER;
pthread_t       vcap_thread;





int ctrl_server()
{
	void *tret;
	int err;

	/*create vctrl thread to monitor usr operations*/
	err = pthread_create(&net_thread, NULL, net_function, NULL);
	if (err!=0)
		printf("can not create vctrl thread\n");

	/*create vctrl thread to monitor usr operations*/
	err = pthread_create(&vctrl_thread, NULL, vctrl_function, NULL);
	if (err!=0)
		printf("can not create vctrl thread\n");

	/*create vcap thread to monitor usr operations*/
	err = pthread_create(&vcap_thread, NULL, video_cap_thread, NULL);
	if (err!=0)
		printf("can not create vcap thread\n");












	err = pthread_join(net_thread, &tret);
	if (err!=0)
		printf("can not join with vctrl thread\n");

	err = pthread_join(vctrl_thread, &tret);
	if (err!=0)
		printf("can not join with vctrl thread\n");

	err = pthread_join(vcap_thread, &tret);
	if (err!=0)
		printf("can not join with vcap thread\n");

	exit(0);
}
